package com.reform.controller.common;


import com.reform.res.Result;
import com.reform.service.ILabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-08-12
 */
@Api(tags = "LabelController")
@RestController
@RequestMapping("/label")
public class LabelController {

    @Autowired
    ILabelService labelService;

    @ApiOperation(value = "创建标签")
    @PostMapping("creatLabel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelName", value = "标签名称", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result creatLabel(String labelName) throws SQLException {
        return labelService.creatLabel(labelName);
    }

    @ApiOperation(value = "删除标签")
    @PostMapping("deleteLabel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelId", value = "标签id", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result deleteLabel(Integer labelId) throws SQLException {
        return labelService.deleteLabel(labelId);
    }

    @ApiOperation(value = "编辑标签")
    @PostMapping("updateLabel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelId", value = "标签id", paramType = "query", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "labelName", value = "标签名称", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result updateLabel(Integer labelId, String labelName) throws SQLException {
        return labelService.updateLabel(labelId, labelName);
    }

    @ApiOperation(value = "获取所有标签")
    @GetMapping("getLabels")
    public Result getLabels() throws SQLException {
        return labelService.getLabels();
    }

}
